package com.liangwj.springbootrabbitmq.rabbit.object;

import com.liangwj.springbootrabbitmq.model.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <b>Description:</b> 高级使用---rabbitMq-object 对象发送 <br/>
 * @author Lingwenjun
 * @date 2019/1/4-17:24
 * @version 1.0
 */
@Component
public class ObjectSender {

    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public ObjectSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void sendObject(User user) {
        System.out.println("Sender object : user = [" + user + "]");
        rabbitTemplate.convertAndSend("user", user);
    }
}
